<?php
 /**************************************************
* PluginLotto.com                                 *
* Copyrights (c) 2005-2010. iZAP                  *
* All rights reserved                             *
***************************************************
* @author iZAP Team "<support@izap.in>"
* @link http://www.izap.in/
* @version {version} $Revision: {revision}
* Under this agreement, No one has rights to sell this script further.
* For more information. Contact "Tarun Jangra<tarun@izap.in>"
* For discussion about corresponding plugins, visit http://www.pluginlotto.com/pg/forums/
* Follow us on http://facebook.com/PluginLotto and http://twitter.com/PluginLotto
 */

// adding poll
$loaded_data = func_load_form_data_byizap($vars['entity']);
?>
<div class="contentWrapper">
    <form action="<?php echo func_get_actions_path_byizap();?>add" method="POST">
    <div>
        <label>
            <?php echo elgg_echo('izap_poll:poll_question')?>*
            <p>
            <?php echo elgg_view('input/text',array(

                'internalname' => 'attributes[_title]',
                'value' => $loaded_data->title,

            ));
                    ?>
            </p>
        </label>
    </div> 
     <?php
     if(!$loaded_data->guid){
    ?>
      <div id="option-array">
      <p id="option1">
        <label>
            <?php echo elgg_echo('izap_poll:poll_option'); ?>
            <?php  echo elgg_view("input/text", array("internalname" => "attributes[option][1]", "js" => "onblur=leave_corresponding_option(1) onfocus=focus_corresponding_option(1) onkeyup=correct_option_label(this.value,1)"))  ?>
        </label>
        <a id="addmore" href="#">Add more</a>
      </p>
    </div>
        <?php
     }
        ?>
        <div>
        <label>
            <?php echo elgg_echo('izap_poll:poll_description')?>
            <p>
            <?php echo elgg_view('input/longtext',array(
                'internalname' => 'attributes[description]',
                'value' => $loaded_data->description,
            ));
                    ?>
            </p>
        </label>

    </div>
        <div>
        <p>
<?php
echo elgg_view('input/hidden', array( 'internalname' => 'attributes[plugin]', 'value' => GLOBAL_IZAP_POLL_PLUGIN));
           echo elgg_view('input/securitytoken');
          echo elgg_view('input/hidden', array(
              'internalname' => 'attributes[access_id]',
               'value' => ACCESS_PUBLIC,
           ));
          echo elgg_view('input/hidden', array('internalname' => 'attributes[guid]', 'value' => (int)$loaded_data->guid));
            ?>
        </p>
        </div>
        <div>
            <label>
                <?php
                echo elgg_echo('izap_poll:tags');
                ?>
            <p>
                <?php
                echo elgg_view('input/tags', array(
                    'internalname' => 'attributes[tags]',
                    'value' => $loaded_data->tags,
                ))
                ?>
            </p>
            </label>
        </div>
        <div>
            <p>
                <?php echo elgg_view('input/submit', array('internalname' => 'sbmt_poll', 'value' => elgg_echo('izap_poll:save') ) ); ?>
            </p>

        </div>
    </form>
</div>

<?php /////// ********    using javascript Add/remove Options      ******** ///////////?>

<script language="javascript" type="text/javascript">
  var counter=2;
  $('document').ready(function(){
    $("#addmore").click(function(){
      $("#option-array").append('<p id="option'+counter+'"><label><?php echo elgg_echo('izap_poll:poll_option')?><input onblur="leave_corresponding_option('+counter+')" onfocus="focus_corresponding_option('+counter+')" onkeyup="correct_option_label(this.value,'+counter+')" type="text" name="attributes[option]['+counter+']" class="input-text"></label><a href="javascript:del_options(\''+counter+'\');">Delete</a></p>');
      
      counter++;
      return false;
    });
  });
  function del_options(id){
    $("#option"+id).remove();
    $("#correct"+id).remove();
  }
  function correct_option_label(str,ctr){
    $("#rlabel"+ctr).text(str).html();
  }

  function focus_corresponding_option(ctr){
    $("#rlabel"+ctr).css('background',"#BFFBB1");
  }
  function leave_corresponding_option(ctr){
    $("#rlabel"+ctr).css('background',"#FFFFFF");
  }
</script>